import React from 'react';
import { useTranslation } from 'react-i18next';
import i18n from '../i18n';

const LanguageSwitcher: React.FC = () => {
  const { t, i18n: { language } } = useTranslation();

  const toggleLanguage = async () => {
    const newLanguage = language === 'en' ? 'zh' : 'en';
    await i18n.changeLanguage(newLanguage);
  };

  return (
    <div>
      <button onClick={toggleLanguage}>
        {t('switchTo')}
      </button>
    </div>
  );
};

export default LanguageSwitcher;